package net.lab1024.smartadmin.module.business.drivecycle.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.module.business.drivecycle.dao.DrivecycleDao;
import net.lab1024.smartadmin.module.business.drivecycle.domain.dto.DrivecycleAddDTO;
import net.lab1024.smartadmin.module.business.drivecycle.domain.dto.DrivecycleQueryDTO;
import net.lab1024.smartadmin.module.business.drivecycle.domain.dto.DrivecycleUpdateDTO;
import net.lab1024.smartadmin.module.business.drivecycle.domain.entity.DrivecycleEntity;
import net.lab1024.smartadmin.module.business.drivecycle.domain.vo.DrivecycleExcelVO;
import net.lab1024.smartadmin.module.business.drivecycle.domain.vo.DrivecycleVO;
import net.lab1024.smartadmin.util.SmartBeanUtil;
import net.lab1024.smartadmin.util.SmartPageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [ 行驶工况特性曲线 (drivecycle) UPDATE  ]
 *
 * @author wuhq
 * @version 1.0
 * @company 汽车传动
 * @copyright (c)  汽车传动Inc. All rights reserved.
 * @date 2021-10-29 20:37:47
 * @since JDK1.8
 */
@Service
public class DrivecycleService {

    @Autowired
    private DrivecycleDao drivecycleDao;

    /**
     * 根据id查询
     */
    public DrivecycleEntity getById(Long id){
        return  drivecycleDao.selectById(id);
    }

    /**
     * 分页查询
     * @author wuhq
     * @date 2021-10-29 20:37:47
     */
    public ResponseDTO<PageResultDTO<DrivecycleVO>> queryByPage(DrivecycleQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        IPage<DrivecycleVO> voList = drivecycleDao.queryByPage(page, queryDTO);
        PageResultDTO<DrivecycleVO> pageResultDTO = SmartPageUtil.convert2PageResult(voList);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 添加
     * @author wuhq
     * @date 2021-10-29 20:37:47
     */
    public ResponseDTO<String> add(DrivecycleAddDTO addDTO) {
        DrivecycleEntity entity = SmartBeanUtil.copy(addDTO, DrivecycleEntity.class);
        drivecycleDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * 编辑
     * @author wuhq
     * @date 2021-10-29 20:37:47
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(DrivecycleUpdateDTO updateDTO) {
        DrivecycleEntity entity = SmartBeanUtil.copy(updateDTO, DrivecycleEntity.class);
        drivecycleDao.updateById(entity);
        return ResponseDTO.succ();
    }

    /**
     * 删除
     * @author wuhq
     * @date 2021-10-29 20:37:47
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        drivecycleDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * 查询全部导出对象
     * @author wuhq
     * @date 2021-10-29 20:37:47
     */
    public List<DrivecycleExcelVO> queryAllExportData(DrivecycleQueryDTO queryDTO) {
        return drivecycleDao.queryAllExportData( queryDTO);
    }

    /**
     * 批量查询导出对象
     * @author wuhq
     * @date 2021-10-29 20:37:47
     */
    public List<DrivecycleExcelVO> queryBatchExportData(List<Long> idList) {
        return drivecycleDao.queryBatchExportData(idList);
    }
}
